<template>
  <div>
    <el-table :data="workInfoTableData" style="width: 100%">
      <el-table-column prop="name" label="标题" width="180"></el-table-column>
      <el-table-column prop="location" label="单位地址" width="180">
      </el-table-column>
      <el-table-column prop="deadline" label="截止时间"></el-table-column>
      <el-table-column prop="people" label="招聘人数"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="editWorkInfo(scope.row)"
            >编辑
          </el-button>
          <el-button type="danger" @click="deleteWorkInfo(scope.row)"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="提示" :visible.sync="dialogVisible" width="60%">
      <el-form :inline="true" :model="formWorkInfo" class="demo-form-inline">
        <el-form-item label="标题">
          <el-input
            v-model="formWorkInfo.title"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="招聘单位">
          <el-input
            v-model="formWorkInfo.place"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="招聘职位">
          <el-input v-model="formWorkInfo.name" placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item label="岗位性质">
          <el-select v-model="formWorkInfo.type" placeholder="请选择">
            <el-option
              v-for="item in workType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单位地址">
          <el-input
            v-model="formWorkInfo.location"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="工作时间">
          <el-input
            v-model="formWorkInfo.worktime"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="工作地点">
          <el-input
            v-model="formWorkInfo.workplace"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="工作报酬">
          <el-input v-model="formWorkInfo.pay" placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item label="截止时间">
          <el-date-picker
            v-model="formWorkInfo.deadline"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="性别要求">
          <el-select v-model="formWorkInfo.sex" placeholder="请选择">
            <el-option
              v-for="item in workSex"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="招聘人数">
          <el-input
            v-model="formWorkInfo.people"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="年纪要求">
          <el-input
            v-model="formWorkInfo.grade"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="校区要求">
          <el-input
            v-model="formWorkInfo.place"
            placeholder="审批人"
          ></el-input>
        </el-form-item>
        <el-form-item label="工作内容">
          <el-input v-model="formWorkInfo.need" placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitEditoWorkInfo"
            >提交</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
Date.prototype.Format = function(fmt) {
  //author: meizz
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + "").substr(4 - RegExp.$1.length)
    );
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
      );
  return fmt;
};
let date = new Date();
let today = date.Format("yyyy-MM-dd");

export default {
  name: "AdminWorkInfo",
  data() {
    return {
      workInfoTableData: null,
      dialogVisible: false,
      workType: [
        { value: "固定", label: "固定" },
        { value: "临时", label: "临时" }
      ],
      workSex: [{ value: "男", label: "男" }, { value: "女", label: "女" }],
      formWorkInfo: {
        id: "",
        name: "",
        publishtime: today,
        title: "",
        type: "",
        worktime: "",
        location: "",
        workplace: "",
        pay: "",
        deadline: "",
        sex: "",
        grade: "",
        place: "",
        need: "",
        people: ""
      }
    };
  },
  mounted() {
    this.getWorkInfoData();
  },
  methods: {
    submitEditoWorkInfo() {
      this.$axios
        .put("/WorkStudyInfo", this.formWorkInfo)
        .then(res => {
          this.$message.success(res.data.message);
        })
        .catch(error => {
          console.log(error);
        });
    },
    editWorkInfo(workInfo) {
      this.formWorkInfo = {
        id: workInfo.id,
        name: workInfo.name,
        publishtime: today,
        title: workInfo.title,
        type: workInfo.type,
        worktime: workInfo.worktime,
        location: workInfo.location,
        workplace: workInfo.workplace,
        pay: workInfo.pay,
        deadline: workInfo.deadline,
        sex: workInfo.sex,
        grade: workInfo.grade,
        place: workInfo.place,
        need: workInfo.need,
        people: workInfo.people
      };
      this.dialogVisible = true;
    },
    getWorkInfoData() {
      this.$axios.get("/WorkStudyInfo").then(res => {
        this.workInfoTableData = res.data.data;
      });
    },
    deleteWorkInfo(workInfo) {
      this.$axios.delete("/WorkStudyInfo/" + workInfo.id).then(res => {
        this.getWorkInfoData();
        this.$message.success("删除成功");
      });
    }
  }
};
</script>

<style scoped></style>
